namespace XEAS.Framework.ShellLib
{
    using System;
    using System.Runtime.InteropServices;

    [Guid("3766C955-DA6F-4fbc-AD36-311E342EF180"), ComVisible(true)]
    public class FilterByExtension : IFolderFilter
    {
        public string[] ValidExtension;

        public int GetEnumFlags(object psf, IntPtr pidlFolder, IntPtr phwnd, out uint pgrfFlags)
        {
            pgrfFlags = 0x60;
            return 0;
        }

        public int ShouldShow(object psf, IntPtr pidlFolder, IntPtr pidlItem)
        {
            ShellApi.STRRET strret;
            string str;
            IShellFolder folder = (IShellFolder) psf;
            folder.GetDisplayNameOf(pidlItem, 0x8000, out strret);
            ShellApi.StrRetToBSTR(ref strret, IntPtr.Zero, out str);
            IntPtr[] apidl = new IntPtr[] { pidlItem };
            uint rgfInOut = 0x20000000;
            int num2 = folder.GetAttributesOf(1, apidl, ref rgfInOut);
            if ((rgfInOut & 0x20000000) == 0x20000000)
            {
                return 0;
            }
            for (int i = 0; i < this.ValidExtension.Length; i++)
            {
                if (str.ToUpper().EndsWith("." + this.ValidExtension[i].ToUpper()))
                {
                    return 0;
                }
            }
            return 1;
        }
    }
}

